const LApp = getApp();

// pages/operat/origins/origins.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
  //id:0
  model:{},
  userInfo:{},
  wxUserInfo:{},
  DataStatistics:{},
  IsExit:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _UserInfo = LApp.globalData.userInfo;
    var _IsExit = _UserInfo.RoleID.searchOf("Ox11") ||
      _UserInfo.RoleID.searchOf("Ox12") ||
      _UserInfo.RoleID.searchOf("Ox13");
    this.setData({
      userInfo: LApp.globalData.userInfo,
      DataStatistics: LApp.globalData.DataStatistics,
      wxUserInfo: LApp.globalData.wxUserInfo,
      IsExit:_IsExit
    })
    this.GetProBatchInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //溯源任务填写
  goOriginHandleTask: function (e) {
   let model = e.currentTarget.dataset.item;
   this.setData({
     model: model
   })
   if (model) {
     LApp.pages.add(this);
     wx.navigateTo({
       url: "originHandleTask/originHandleTask",
     })

   }  

  },
  //get 产品批次信息
  GetProBatchInfo:function(){
    let _this = this;
    LApp._get({
      url: 'nbapi/product/batch/list',
      data: { pageIndex: 1, pageSize: 10, Psearch: " " },
      success: function (r) {
        _this.setData({
          ProBatchList: r
        })
      }
    })  

  },
  openScan:function(){
let _this=this;
    wx.scanCode({
      onlyFromCamera: true,
      success: function (res) {
        if (res)
        {
          var result=res.result;
          _this.GetBarchId(result);
         
        }
      }
    })
  },
  GetBarchId:function(url){
    let _this=this;
    LApp._get({
      url: 'nbapi/originsTask/origins/codesearch',
      data: { url: url },
      success: function (res) {
        _this.data.model=res;
       //跳转页面
        LApp.pages.add(_this);
        wx.navigateTo({
          url: "originHandleTask/originHandleTask",
        })
      },
      fail: function (ex) {
       wx.showModal({
         title: '提示',
         content: ex,
       })
      }

    })
  },
  loginOut: function () {
    try {
      wx.clearStorageSync()
    } catch (e) {
      // Do something when catch error
    };
    LApp.globalData.userInfo = undefined;
    wx.reLaunch({
      url: '../../my/logon/guide/guide',
    })
  }
})